
/**
 * Copyright 2009 cestum.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.waveprotocol.wave.model.document.operation.impl.impl {
import org.waveprotocol.wave.model.document.operation.AnnotationBoundaryMap;
import org.waveprotocol.wave.model.document.operation.Attributes;
import org.waveprotocol.wave.model.document.operation.BufferedDocOp;
import org.waveprotocol.wave.model.document.operation.DocInitializationComponentType;
import org.waveprotocol.wave.model.document.operation.DocInitializationCursor;
import org.waveprotocol.wave.model.document.operation.DocOpComponentType;  import org.waveprotocol.wave.model.document.operation.util.DocOpComponentConstants;
import org.waveprotocol.wave.model.document.operation.DocumentOperationCursor;
import org.waveprotocol.wave.model.document.operation.impl.AbstractBufferedDocInitialization;
import org.waveprotocol.wave.model.document.operation.impl.InitializationCursorAdapter;

public class CursorAdapterBufferedDocInitialization extends
	AbstractBufferedDocInitialization {
	var op:BufferedDocOp;
	public function CursorAdapterBufferedDocInitialization(op:BufferedDocOp) {
		this.op = op;
	}
	
	override public function applyDocInit(c:DocInitializationCursor):void {
		op.apply(new InitializationCursorAdapter(c));
	}
	
	override public function applyComponentDocInit(i:int, c:DocInitializationCursor):void {
		op.applyComponent(i, new InitializationCursorAdapter(c));
	}
	
	
	override public function applyComponent(i:int, c:DocumentOperationCursor):void {
		op.applyComponent(i, new InitializationCursorAdapter(c));
	}
	
	
	override public function getAnnotationBoundary(i:int):AnnotationBoundaryMap {
		return op.getAnnotationBoundary(i);
	}
	
	
	override  public function getCharactersString(i:int):String {
		return op.getCharactersString(i);
	}
	
	override public function getElementStartAttributes(i:int):Attributes {
		return op.getElementStartAttributes(i);
	}
	
	override  public function getElementStartTag(i:int):String {
		return op.getElementStartTag(i);
	}
	
	override public function getTypeInit(i:int):DocInitializationComponentType {
		var t:DocOpComponentType= op.getType(i);
		if (t instanceof DocInitializationComponentType) {
			return DocInitializationComponentType(t);
		} else {
			throw new Error(
				"Unsupported Exception: Initialization with unexpected component " + t + ": " + op);
		}
	}
	
	override public function size():int {
		return op.size();
	}
}
}